package com.learn.tools.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/**
 * 项目内获取spring bean的工具
 *
 * @author: liangan
 * @version  1.0.0
 */
public class SpringBeanTool implements BeanFactoryAware {

	private static BeanFactory beanFactory = null;

	@Override
	public void setBeanFactory(BeanFactory bf) throws BeansException {
		SpringBeanTool.beanFactory = bf;
	}

	public static Object getBean(String beanName) {
		return beanFactory.getBean(beanName);
	}

	public static Object getBean(Class<?> type) {
		return beanFactory.getBean(type);
	}
}
